package com.example.hello.client.NavForm;

import com.example.hello.BootstrapNavForm;
import com.github.gwtbootstrap.client.ui.constants.Alignment;
import com.github.gwtbootstrap.client.ui.constants.FormType;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.ui.Widget;
import com.vaadin.client.communication.StateChangeEvent;
import com.vaadin.client.ui.AbstractComponentConnector;
import com.vaadin.shared.ui.Connect;

@Connect(BootstrapNavForm.class)
public class BootstrapNavFormConnector extends AbstractComponentConnector {

    @Override
    protected Widget createWidget() {
        return GWT.create(VBootstrapNavForm.class);
    }

    @Override
    public BootstrapNavFormState getState() {
        return (BootstrapNavFormState) super.getState();
    }

    @Override
    public VBootstrapNavForm getWidget() {
        return (VBootstrapNavForm) super.getWidget();
    }

    @Override
    public void onStateChanged(StateChangeEvent stateChangeEvent) {
        super.onStateChanged(stateChangeEvent);

        BootstrapNavFormState state = getState();

        VBootstrapNavForm navForm = getWidget();

        navForm.setPlaceholder(state.getPlaceholder());
        navForm.setAlignment(Alignment.valueOf(state.getAlignment()));
        navForm.setType(FormType.valueOf(state.getType()));
        navForm.setSize(state.getSize());
    }

}